from .models import CourseCategory, Course
from rest_framework.generics import ListAPIView
from .serializers import CourseCategoryModelSerializer, CourseSerializer


class CourseCategoryListAPIView(ListAPIView):
    queryset = CourseCategory.objects.filter(is_show=True, is_delete=False).order_by("-orders", "-id")
    serializer_class = CourseCategoryModelSerializer
    pagination_class = None


from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import OrderingFilter
from .paginations import CoursePageNumberPagination


class CourseAPIView(ListAPIView):
    """课程列表接口"""
    queryset = Course.objects.filter(is_delete=False, is_show=True).order_by("orders", '-id')
    serializer_class = CourseSerializer
    pagination_class = CoursePageNumberPagination
    filter_backends = [DjangoFilterBackend, OrderingFilter]
    filter_fields = ('course_category',)
    ordering_fields = ('id', 'students', 'price')
